package com.rpay.dao.user;

import com.google.common.collect.Maps;
import com.rpay.model.admin.AdminUserDO;
import com.rpay.model.user.UserDO;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Title：
 * Description
 *
 * @author fxg06 on 2018/4/20
 * @version 1.0
 */
@Repository
public class UserDao {

    @Autowired
    @Qualifier("readSqlSession")
    private SqlSessionTemplate readSqlSession;

    @Autowired
    @Qualifier("writeSqlSession")
    private SqlSessionTemplate writeSqlSession;

    public UserDO selectUser(String account) {
        return readSqlSession.selectOne("rpay.user.selectUser", account);
    }

    public int insert(UserDO userDO) {
        return writeSqlSession.insert("rpay.user.insert", userDO);
    }

    public int update(UserDO userDO) {
        return writeSqlSession.update("rpay.user.update", userDO);
    }

    public UserDO selectById(Integer id) {
        return readSqlSession.selectOne("rpay.user.selectById", id);
    }

    public UserDO selectByShareCode(String shareCode) {
        return readSqlSession.selectOne("rpay.user.selectByShareCode", shareCode);
    }

    public List<UserDO> selectAll(String teamKey) {
        return readSqlSession.selectList("rpay.user.selectAll", teamKey);
    }

    public List<UserDO> selectAllByRootUserId(Integer rootUserId) {
        Map param = new HashMap();
        param.put("rootUserId", rootUserId);
        return readSqlSession.selectList("rpay.user.selectAllByRootUserId", param);
    }

    public int selectCountByLevel(Integer level) {
        return readSqlSession.selectOne("rpay.user.selectCountByLevel", level);
    }

    public List<UserDO> selectUsers(String teamKey) {
        return readSqlSession.selectList("rpay.user.selectUsers", teamKey);
    }

    public UserDO selectUserById(Integer id) {
        return readSqlSession.selectOne("rpay.user.selectUserById", id);
    }

    public List<UserDO> selectByParentId(Integer parentId) {
        return readSqlSession.selectList("rpay.user.selectByParentId", parentId);
    }

    public List<UserDO> selectByParentIdandKeyword(Map param) {
        return readSqlSession.selectList("rpay.user.selectByParentIdAndKeyword", param);
    }

    public List<UserDO> selectUsersByKeyword(Map param) {
        return readSqlSession.selectList("rpay.user.selectUsersByKeyword", param);
    }

    public int upgrade(List<UserDO> list) {
        return writeSqlSession.update("rpay.user.upgrade", list);
    }
}
